package com.ruoyi.web.controller.lwpq;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.lwpq.domain.LwpqCwgl;
import com.ruoyi.lwpq.service.ILwpqCwglService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 财务管理Controller
 * 
 * @author ruoyi
 * @date 2022-03-16
 */
@Controller
@RequestMapping("/lwpq/cwgl")
public class LwpqCwglController extends BaseController
{
    private String prefix = "lwpq/cwgl";

    @Autowired
    private ILwpqCwglService lwpqCwglService;

    @RequiresPermissions("lwpq:cwgl:view")
    @GetMapping()
    public String cwgl()
    {
        return prefix + "/cwgl";
    }

    /**
     * 查询财务管理列表
     */
    @RequiresPermissions("lwpq:cwgl:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(LwpqCwgl lwpqCwgl)
    {
        startPage();
        lwpqCwgl.setCreateBy(getLoginName());
        List<LwpqCwgl> list = lwpqCwglService.selectLwpqCwglList(lwpqCwgl);
        return getDataTable(list);
    }

    /**
     * 导出财务管理列表
     */
    @RequiresPermissions("lwpq:cwgl:export")
    @Log(title = "财务管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(LwpqCwgl lwpqCwgl)
    {
        List<LwpqCwgl> list = lwpqCwglService.selectLwpqCwglList(lwpqCwgl);
        ExcelUtil<LwpqCwgl> util = new ExcelUtil<LwpqCwgl>(LwpqCwgl.class);
        return util.exportExcel(list, "财务管理数据");
    }

    /**
     * 新增财务管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存财务管理
     */
    @RequiresPermissions("lwpq:cwgl:add")
    @Log(title = "财务管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(LwpqCwgl lwpqCwgl)
    {
        lwpqCwgl.setCreateBy(getLoginName());
        return toAjax(lwpqCwglService.insertLwpqCwgl(lwpqCwgl));
    }

    /**
     * 修改财务管理
     */
    @RequiresPermissions("lwpq:cwgl:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        LwpqCwgl lwpqCwgl = lwpqCwglService.selectLwpqCwglById(id);
        mmap.put("lwpqCwgl", lwpqCwgl);
        return prefix + "/edit";
    }

    /**
     * 修改保存财务管理
     */
    @RequiresPermissions("lwpq:cwgl:edit")
    @Log(title = "财务管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(LwpqCwgl lwpqCwgl)
    {
        lwpqCwgl.setUpdateBy(getLoginName());
        return toAjax(lwpqCwglService.updateLwpqCwgl(lwpqCwgl));
    }

    /**
     * 删除财务管理
     */
    @RequiresPermissions("lwpq:cwgl:remove")
    @Log(title = "财务管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(lwpqCwglService.deleteLwpqCwglByIds(ids));
    }
}
